#include "widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::WidgetClass())
{
    ui->setupUi(this);

    

}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_GetDateTime_clicked()
{
    QDateTime dateTimeNow = QDateTime::currentDateTime();

    ui->timeEdit->setTime(dateTimeNow.time());
    ui->lineEdit_Time->setText(dateTimeNow.toString("hh:mm:ss"));

    ui->dateEdit->setDate(dateTimeNow.date());
    ui->lineEdit_Date->setText(dateTimeNow.toString("yyyy-MM-dd"));

    ui->dateTimeEdit->setDateTime(dateTimeNow);
    ui->lineEdit_DateTime->setText(dateTimeNow.toString("yyyy-MM-dd hh:mm:ss"));
}

void Widget::on_pushButton_SetTime_clicked()
{
    QString str = ui->lineEdit_Time->text();
    str = str.trimmed();
    if (!str.isEmpty())
    {
        QTime tim = QTime::fromString(str, "hh:mm:ss");
        ui->timeEdit->setTime(tim);
    }
}

void Widget::on_pushButton_SetDate_clicked()
{
    QString str = ui->lineEdit_Date->text();
    str = str.trimmed();
    if (!str.isEmpty())
    {
        QDate da = QDate::fromString(str, "yyyy-MM-dd");
        ui->dateEdit->setDate(da);
    }
}

void Widget::on_pushButton_SetTimeDate_clicked()
{
    QString str = ui->lineEdit_DateTime->text();
    str = str.trimmed();
    if (!str.isEmpty())
    {
        QDateTime dt = QDateTime::fromString(str, "yyyy-MM-dd hh:mm:ss");
        ui->dateTimeEdit->setDateTime(dt);
    }
}

void Widget::on_calendarWidget_selectionChanged()
{
    QString str = ui->calendarWidget->selectedDate().toString("yyyy年MM月dd日");
    ui->lineEdit_Calendar->setText(str);
}